package com.likan.chqjtgc.service.impl;

import com.likan.chqjtgc.commons.PageVo;
import com.likan.chqjtgc.entity.BasicUserRole;
import com.likan.chqjtgc.mapper.BasicUserRoleMapper;
import com.likan.chqjtgc.service.BasicUserRoleService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.apache.commons.lang3.StringUtils;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 角色表 服务实现类
 * </p>
 *
 * @author lxh
 * @since 2021-01-10
 */
@Service
@Transactional(rollbackFor = {Exception.class})
public class BasicUserRoleServiceImpl extends ServiceImpl<BasicUserRoleMapper, BasicUserRole> implements BasicUserRoleService {

    @Autowired
    private BasicUserRoleMapper baseMapper;

    @Override
    public IPage<BasicUserRole> findListByPage(PageVo< BasicUserRole> page){
           Page<BasicUserRole> pageInfo = new Page<>(page.getCurrent(), page.getSize());
       QueryWrapper<BasicUserRole> wrapper = new QueryWrapper<>();
        //todo:构造查询参数 根据业务添加

       if (StringUtils.isNotBlank(page.getSortField())){
           wrapper.orderBy(true,0!=page.getDirection() ,page.getSortField());
       }else {
           wrapper.orderByDesc("id");
       }
        IPage<BasicUserRole> iPage = baseMapper.selectPage(pageInfo, wrapper);
        return iPage;
    }

    @Override
    public Boolean add(BasicUserRole basicUserRole){
        baseMapper.insert(basicUserRole);
        return true;
    }

    @Override
    public Boolean delete(Long id){
        baseMapper.deleteById(id);
        return true;
    }

    @Override
    public Boolean updateData(BasicUserRole basicUserRole){
        baseMapper.updateById(basicUserRole);
        return true;
    }

    @Override
    public BasicUserRole findById(Long id){
        BasicUserRole basicUserRole = baseMapper.selectById(id);
        return basicUserRole;
    }
}
